﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Statistic
{
    public static class HtmlString
    {
        /**
         * Check if page exists
         * @param url
         *   html page
         * @return result_
         *   True if exists False if page doesn't exist
         */
        public static bool PageExists(string source, string message)
        {
            int FirstChr = source.IndexOf(message);
            if (FirstChr == -1)
                return true;
            else
                return false;
        }

        /**
* Cleans source code from html tags
* @param source
*   source code to be cleaned
* @return
*   clened source code
*/
        public static string StripTagsCharArray(string source)
        {
            char[] array = new char[source.Length];
            int arrayIndex = 0;
            bool inside = false;

            for (int i = 0; i < source.Length; i++)
            {
                char let = source[i];
                if (let == '<')
                {
                    inside = true;
                    continue;
                }
                if (let == '>')
                {
                    inside = false;
                    continue;
                }
                if (!inside)
                {
                    array[arrayIndex] = let;
                    arrayIndex++;
                }
            }
            return new string(array, 0, arrayIndex);
        }
    }
}